#write.table(mergedarray,"/data2/bsi/RandD/bora/OV_EQTL/AFFY_ILL_MERGED/Merged_PVAL_temp.txt",sep="\t",quote=F,row.names=F,col.names=T)a
mergedarray<-read.table("/data2/bsi/RandD/bora/OV_EQTL/AFFY_ILL_MERGED/Merged_PVAL_temp.txt",sep="\t",head=T)
mergedarray<-mergedarray[with(mergedarray, order(PVAL)), ]
write.table(mergedarray,"/data2/bsi/RandD/bora/OV_EQTL/AFFY_ILL_MERGED/Merged_PVAL_sorted.txt",sep="\t",quote=F,row.names=F,col.names=T)
CountMySignificant <- function(x)
{
              count = 0
              for(i in 3:length(x))
    {
        if(x[i] < x[2] && !is.na(x[i]))
        {
              count = count + 1
        }
     }
     return(count)
}
CountNA<-function(x)
{
                return(sum ( is.na (x)))
}
colnames<-colnames(mergedarray)
NA_count<-apply(mergedarray,1,CountNA)
Count<-apply(mergedarray,1,CountMySignificant)
mergedarray<-cbind(mergedarray,NA_count,Count)
colnames(mergedarray)<-c(colnames,"NA_COUNT","PVALCOUNT")
write.table(mergedarray,"/data2/bsi/RandD/bora/OV_EQTL/AFFY_ILL_MERGED/Merged_PVAL.txt",sep="\t",quote=F,row.names=F,col.names=T)
